home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: news.sprintlink.net!eskimo!scs
- From: scs@eskimo.com (Steve Summit)
- Subject: Re: Problem with sscanf on DEC Alpha
- X-Nntp-Posting-Host: eskimo.com
- Message-ID: <DL37x0.Jo4@eskimo.com>
- Sender: news@eskimo.com (News User Id)
- Organization: schmorganization
- References: <4d3f0c$mfq@colossus.holonet.net>
- Date: Fri, 12 Jan 1996 21:34:11 GMT
-
- In article <4d3f0c$mfq@colossus.holonet.net>, mitch@news.mdli.com
- (Mitch Miller) writes:
- > I'm having a problem with a line in my program:
- >
- > sscanf( sInputLine, "%3d%3d%10.4f%10.4f", &iAtom1,
- > &iAtom2, &(F3D->r3DV1), &(F3D->r3DV2) );
- >
- > F3D is a pointer to struct and the struct has double members
- > r3DV1 and r3DV2.
- >
- > When I've compiled/run this on a VAX, both F3D->r3DV1 and F3D->r3DV2
- > get assigned correctly 9.4 and 10.5. However, on the Alpha, both
- > end up as 0.0.
-
- It works on a VAX because the VAX uses what I call "little endian
- floating point": a float value is a proper subset of a double; if
- you take a pointer to a double value, and look at the first
- sizeof(float) bytes there, they represent a valid float value.
- This is, however, not at all universal, and on most machines, if
- you're careless about pointer-to-float vs. pointer-to-double,
- things don't work to well.
-
- How are pointers-to-float involved in your problem? They're what
- scanf's %f format expects. The comp.lang.c FAQ list explains why;
- here's the text from the book-length version (Addison-Wesley,
- 1996, ISBN 0-201-84519-9):
-
- 12.13: Why doesn't this code:
-
- double d;
- scanf("%f", &d);
-
- work?
-
- A: Unlike printf(), scanf() uses %lf for values of type double, and
- %f for float. [1] %f tells scanf() to expect a pointer-to-
- float, not the pointer-to-double you gave it. Either use %lf,
- or declare the receiving variable as a float. See also question
- 12.9.
-
- __________
- 1. Everything said here is equally true of %e and %g, and their
- companion formats %le and %lg.
-
- Steve Summit
- scs@eskimo.com
-